package org.example.JUC.Tools;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-10 18:30
 **/
public class SemaphoreTest {
    private static Semaphore semaphore=new Semaphore(0);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService= Executors.newFixedThreadPool(2);
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread()+"over");
                semaphore.release();
            }
        });

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread()+"over");
                semaphore.release();
            }
        });

        semaphore.acquire(2);
        System.out.println("all child thread over");
        executorService.shutdown();
    }
}